﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace EDMS
{
    public partial class UpdateSelection : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                initSelection();
            }

        }
        //确定修改
        protected void btnOK_Click(object sender, EventArgs e)
        {
            updateSelection();
        }
        //取消
        protected void btnEsc_Click(object sender, EventArgs e)
        {

        }
        //初始化数据
        private void initSelection()
        {
            using (DataClassesDataContext dc = new DataClassesDataContext())
            {
                var sel = from s in dc.Xjdj
                          where s.xjbh == Request.QueryString["SID"]
                          select new
                          {
                              bh = s.xjbh,
                              mc = s.xjmc,
                              sj = s.xjsj,
                              jssj = s.wtjssj,
                              bj = s.flag,
                          };
                foreach (var i in sel)
                {
                    txtXjbh.Text = i.bh;
                    txtXjmc.Text = i.mc;
                    deXjsj.Value = i.sj.ToShortDateString();
                    deWtjssj.Value = i.jssj.ToShortDateString();
                }
            }
        }
        //更新数据
        private void updateSelection()
        {
            using (DataClassesDataContext dc = new DataClassesDataContext())
            {
                var se = dc.Xjdj.Select(s => s)
                    .Where(s => s.xjbh == Request.QueryString["SID"])
                    .SingleOrDefault();
                se.xjmc = txtXjmc.Text.Trim().ToString();
                se.xjsj = Convert.ToDateTime(deXjsj.Text);
                se.wtjssj = Convert.ToDateTime(deWtjssj.Text);
                dc.SubmitChanges();
                Frame.Global.GlobalFunctions.Alert("选举信息修改成功！");
            };

        }
    }
}